package com.ruoyi.project.service.email;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService {
    private final JavaMailSender mailSender;

    public EmailService(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     * 发送验证码到用户邮箱
     * @param to 邮箱地址
     * @param verificationCode 验证码
     * @return 是否成功发送
     */
    public boolean sendVerificationCode(String to, String verificationCode) {
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("1650632439@qq.com");
            message.setTo(to);
            message.setSubject("邮箱验证码");
            message.setText("您的验证码是：" + verificationCode);
            mailSender.send(message);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

